﻿using nplJobsCommon.JobSeeker;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nplJobsDAL.Insert
{
    public class InsertJobSeekerEducationInfo : DataAccessBase
    {
    
        public Int64 lastJobSeekerEducationInfoID;
        public string CheckUnique;
        
        public EducationInfo EducationInfo { get; set; }

        public InsertJobSeekerEducationInfo()
        {
            StoredProcedureName = StoredProcedure.Name.spInsertJobSeekerEducationInfo.ToString();
        }

        public void Insert()
        {
            InsertEducationInfoDataParameters educationInfoInsertDataParameters = new InsertEducationInfoDataParameters(this.EducationInfo);
            DataBaseHelper dbHelper = new DataBaseHelper(StoredProcedureName);
            dbHelper.Parameters = educationInfoInsertDataParameters.Parameters;
            object LastJobSeekerEducationInfoID = dbHelper.RunScalar();

            if (LastJobSeekerEducationInfoID != null)
            {
                lastJobSeekerEducationInfoID = (Int64)LastJobSeekerEducationInfoID;
            }
            else
            {
                lastJobSeekerEducationInfoID = -1;
            }
        }
    }

    #region SQL parameters for education info data parameters
    public class InsertEducationInfoDataParameters
    {      
        public int CkeckUnique;
        private SqlParameter[] _parameters;
        public int lastJobSeekerEducationInfoID;

        public InsertEducationInfoDataParameters(EducationInfo educationinfo)
        {
            this.EducationInfo = educationinfo;
            Build();
        }
        
        private void Build()
        {
            SqlParameter[] parameters = 
                {
                    new SqlParameter("@JobSeekerID", EducationInfo.JobSeekerID),
                    new SqlParameter("@InstitutionName", EducationInfo.InstitutionName),
                    new SqlParameter("@FieldOfStudyID", EducationInfo.FieldOfStudyID),
                    new SqlParameter("@SpecializedSubjects", EducationInfo.SpecializedSubjects),
                    new SqlParameter("@Degree", EducationInfo.Degree),
                    new SqlParameter("@Grade", EducationInfo.Grade),
                    new SqlParameter("@FromDate", EducationInfo.FromDate),
                    new SqlParameter("@ToDate", EducationInfo.ToDate),
                    new SqlParameter("@IsDeleted", EducationInfo.IsDeleted),
                    new SqlParameter("@EducationInfoID", EducationInfo.EducationInfoID),
                    new SqlParameter("@EduInfoID", lastJobSeekerEducationInfoID){ Direction= System.Data.ParameterDirection.ReturnValue},
                 
                };

            Parameters = parameters;
        }

        public EducationInfo EducationInfo { get; set; }

        public SqlParameter[] Parameters
        {
            get { return _parameters; }
            set { _parameters = value; }
        }
    }
    #endregion
}

